<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Webservices extends CI_Controller {

	public function index(){
		
		$wfid = $this->uri->segment(3, 0);
 		$this->load->model('workflowmodel','workflow');
		$dataobj=$this->workflow->getworkflowarray($wfid);
		$this->load->view('header2');
		
		$data=array(
			'workflowname'=>$dataobj['workflow_name'],
			'workflowid'=>$wfid
			
		);
		
		$this->load->view('wftestindex',$data);
		
	}
	
	public function disp(){
		$wfid=$this->input->post("wfid",TRUE);
		$products=$this->input->post("arrayString",TRUE);
		$this->load->model('workflowmodel','workflow');
		$dataobj=$this->workflow->getworkflowarray($wfid);
		
		foreach($dataobj['service_array'] as $service){
				
			$this->workflow->fetchhtmlfromservice($service['descr'],$products);
			echo '</br>';
		}
		
		
	}
	
	public function calculateTotal(){
//		http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl
		$totaljson=$this->input->post("totaljson",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->calculateTotal(array('request'=>$totaljson));
		
		echo $result->return;
	}
	
	public function calculateTax(){
		$total=$this->input->post("total",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->calculateTax(array('costPrice'=>$total));
		
		echo $result->return;
		
	}
	
	public function applyCoupon(){
		$coupon=$this->input->post("coupontext",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->availCoupon(array('couponCode'=>$coupon));
		
		echo $result->return;
	}
	
	public function shippingCharges(){
		$shiptext=$this->input->post("shippingtext",TRUE);
		$quantity=$this->input->post("quantity",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->shippingCharges(array('quantity'=>$quantity,'pinCode'=>$shiptext));
		
		echo $result->return;
	}
	
	public function confirmation(){
		
	}
	
	public function confirmationViaEmail(){
		
	}
	
	public function mailInvoice(){
		
	}
	
	public function wrapGift(){
		
		
	}
	
	public function promotions(){

		
		
	}
	
	public function getCaptcha(){
		
	}
	
	public function similiarProductSuggestions(){
		$totaljson=$this->input->post("totaljson",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->productSuggestions(array('jsonReq'=>$totaljson));

		$data=json_decode($result->return);
		
		print_r($data);
		
		$this->load->model('workflowmodel','workflow');
		
		echo "<ul>";
		foreach($data as $service){
			$val=$this->workflow->getProduct($service);
			echo "<li>".$val['name']."</li>";
		}
		echo "</ul>";
	}
	
	public function makePayment(){
		
		$cctext=$this->input->post("cctext",TRUE);
		$client=new SoapClient("http://localhost:8080/SunShopWebSevice/services/OtherWebServices?wsdl");
		$result=$client->makePayment(array('cardno'=>$cctext,'cvv'=>">","expiry"=>"","amount"=>""));
		
		echo $result->return;
		
		
	}
	
	
}